package com.shunwang.htmlparser.controller;

import java.io.IOException;
import java.util.List;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import com.shunwang.caipiao.data.pojo.DoubleColor;
import com.shunwang.htmlparser.generator.DocumentGenerator;
import com.shunwang.htmlparser.generator.impl.DocumentUrlGenerator;
import com.shunwang.htmlparser.parser.DocumentCollectionParser;
import com.shunwang.htmlparser.parser.DoubleColorParser;
import com.shunwang.htmlparser.searcher.DocumentSearcher;
import com.shunwang.htmlparser.searcher.DoubleColorSearcher;

public class SimpleController {

	private DocumentGenerator<String> generator = new DocumentUrlGenerator<String>();
	private DocumentCollectionParser parser = new DoubleColorParser();
	private DocumentSearcher searcher = new DoubleColorSearcher();
	
	public List<DoubleColor> getDoubleColor(String url) throws IOException{
		Document doc = generator.generator(url);
		if(doc == null){
			return null;
		}
		Element element = searcher.searcher(doc);
		if(element == null){
			return null;
		}
		return parser.parser(element);
	}
}
